package com.s59.crm;

import lombok.Data;

@Data
public class Result<T> {
    public static final int SUCCESS = 200;
    public static final int FAILED = 500;

    private int code = SUCCESS;
    private String message = "success";

    private T data;

    public Result() {

    }

    private Result(int code, String message, T data){
            this.code=code;
            this.message=message;
            this.data=data;
    }

    public static<T> Result ok(){
        return new Result(SUCCESS,"success",null);
    }

    public static<T> Result ok(int code,String message){
        return new Result(code,message,null);
    }

    public static<T> Result ok(T data){
        return new Result(SUCCESS,"success",data);
    }

    public static <T> Result<T> error(){
        return new Result(FAILED,"error",null);
    }

    public static <T> Result<T> error(int code,String message){
        return new Result(code,message,null);
    }

    public static <T> Result<T> error(String message){
        return new Result(FAILED,message,null);
    }

}
